package com.stox.client.ui.javafx.chartingy.model.node;

import javafx.scene.paint.Color;

import com.stox.client.ui.javafx.chartingy.model.plot.Data;
import com.stox.shared.model.Bar;
import com.stox.shared.model.Scrip;

public abstract class AbstractPriceNode extends DataNode<Scrip, Bar> {

	protected Color color = Color.YELLOW;

	public AbstractPriceNode(final Data<Scrip, Bar> data) {
		super(data);
	}

	@Override
	public Color getColor() {
		return color;
	}

	public void updateColor() {
		if (getData().getPlot().isPrimary()) {
			final Data<Scrip, Bar> data = getData();
			final Bar bar = data.getExtraValue();
			final int size = data.getPlot().getData().size();
			if (data.getIndex() < (size - 1)) {
				final Bar previousBar = data.getPlot().getData().get(data.getIndex() + 1).getExtraValue();
				color = previousBar.getClose() < bar.getClose() ? Color.GREEN : (previousBar.getClose() == bar.getClose() ? Color.YELLOW : Color.RED);
			}
		} else {
			color = super.getColor();
		}
	}

}
